// {
// 	id: 1,
// 	name: 'jack'
// },


// id=1&name=jack

function resolve(obj) {
	var arr = []
	for (const key in obj) {
		//console.log(key, obj[key]);
		var str = key + '=' + obj[key] //   id=1   name=jack
		arr.push(str)
	}
	//console.log(arr.join('&')); //  [id=1,name=jack]
	return arr.join('&') //   id=1&name=jack&age=19
}


function itheima(option) {
	var q = resolve(option.data) //   id=1&name=jack&age=19
	let xhr = new XMLHttpRequest()
	/* 判断是post还是get */
	if (option.method.toUpperCase() == 'GET') {
		xhr.open(option.method, option.url + "?" + q)
		xhr.send()
	} else if (option.method.toUpperCase() == 'POST') {
		/* 
		设置请求头 +  参数在send中传递
		 */
		xhr.open(option.method, option.url)
		xhr.setRequestHeader("Content-Type", 'application/x-www-form-urlencoded')
		xhr.send(q)
	}

	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4 && xhr.status == 200) {
			//  获取数据
			//let res = xhr.responseText

			option.success && option.success(xhr.responseText)
		}
	}
}
